package com.kcloud.commons.entity.control;

import com.kcloud.commons.entity.core.StandardAttribute;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 属性
 */
@Data
@NoArgsConstructor
public class Attribute implements StandardAttribute {

    /**
     * 属性类型：操作 opt
     */
    public static final String ATTR_TYPE_OPT = "opt";
    /**
     * 属性类型：全局操作 globalOpt
     */
    public static final String ATTR_TYPE_GLOBAL_OPT = "globalOpt";
    /**
     * 属性类型：属性 attr
     */
    public static final String ATTR_TYPE_ATTR = "attr";
    private String attrName; //属性名称
    private String attrCode; //属性编码
    private String attrType; // 属性类型，默认为属性
    private String format; // 格式要求
    private String customValidation; //其他校验
    private String customDescription; // 其他说明
    private String columnName; //数据库列名
    private Boolean primaryKey; // 是否为主键
    private Boolean foreignKey; //是否为键
    private Boolean timestamp; // 是否为时间戳

    private String icon;// 图标
    private String displayName; // 显示名称
    private boolean required; //是否必填
    private int formOrder; // 表单顺序
    private int tableHeaderOrder; // 表头顺序
    private Boolean showTable = true; // 是否列表显示
    private Boolean showForm = true; // 是否表单显示
    private Boolean defaultOrder; //列表默认排序
    private String displayGroup; // 显示分组
    private Boolean query = true; // 是否是查询条件
    private int ctrlType;
    private Boolean checked = false;


    public Attribute(String attrCode, String attrName, boolean primaryKey, boolean foreignKey) {
        this.attrCode = attrCode;
        this.attrName = attrName;
        this.attrType = ATTR_TYPE_ATTR;
        this.primaryKey = primaryKey;
        this.foreignKey = foreignKey;
    }
    /**
     * 必要的属性
     * @return
     */
    public boolean requiredAttr() {
        return primaryKey || foreignKey || timestamp;
    }

    @Override
    public void setTitle(String title) {
        this.attrName = title;
    }

    @Override
    public void setKey(String key) {
        this.attrCode = key;
    }


    @Override
    public void setType(String type) {
        this.attrType = type;
    }


    @Override
    public String getTitle() {
        return this.attrName;
    }

    @Override
    public String getKey() {
        return this.attrCode;
    }


    @Override
    public String getType() {
        return this.attrType;
    }
}
